package com.ljfiction.book.activitys;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ljfiction.book.MyView.ContainsEmojiEditText;
import com.ljfiction.book.R;
import com.ljfiction.book.tools.StringTool;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class AuthorSayActivity extends BaseActivity {

    @BindView(R.id.authorsay_back)
    ImageView authorsayBack;
    @BindView(R.id.author_say_ok)
    TextView authorSayOk;
    @BindView(R.id.authorsay_text)
    ContainsEmojiEditText authorsayText;
    @BindView(R.id.num_authorsay)
    TextView numAuthorsay;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_author_say);
        ButterKnife.bind(this);
        if (!getIntent().getStringExtra("authorsay").equals("作者什么都没说")){
            authorsayText.setText(getIntent().getStringExtra("authorsay"));
        }
        intView();
    }

    private void intView() {
authorsayText.addTextChangedListener(new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        if (String.valueOf(s).length() >= 200) {
            showToast("字数不能大于200哦");
        }
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

        numAuthorsay.setText(String.valueOf(s).length() + "/200");
    }

    @Override
    public void afterTextChanged(Editable s) {

    }
});
    }

    @OnClick({R.id.authorsay_back, R.id.author_say_ok})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.authorsay_back:
                goBack();
                break;
            case R.id.author_say_ok:
                if (StringTool.isEmpty(authorsayText.getText().toString())){
                    showToast("作者的话不能为空哦！");
                }else {
                    Intent intent=new Intent();
                    intent.putExtra("authorsay",authorsayText.getText().toString());
                    setResult(10,intent);
                    goBack();
                }
                break;
        }
    }
}
